package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import java.util.List;

import com.iwhalecloud.bss.kite.common.util.KiteBeanUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.dataservice.cache.AttrValueCache;
import com.iwhalecloud.bss.kite.dataservice.entity.AttrValue;
import com.iwhalecloud.bss.kite.manager.enums.ActionType;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttrValue;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;

public class ApnOperTypeAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {

    @Override
    public void onShow(KiteAttr attr, KiteInst inst, AttrData data) {
        // 新增APN方式，我要定制100006952
        // APN类型-200003999，互联网100003262，VPDN100006957
        // 细分业务类型-200004001：黑名单100006959，白名单100006958，互联网GRE100006960，互联网L2TP100006961,专线GRE100006962,专线L2TP100006963
        String apnType = inst.getAttrValue("200003999");
        String busiType = inst.getAttrValue("200004001");
        List<AttrValue> operTypes = AttrValueCache.get(attr.getAttrId());
        // 新增，展示新装
        if (KiteStringUtils.equals(ActionType.A.name(), inst.getActionType().name())) {
            //operTypes.removeIf(_attr -> !KiteStringUtils.equals(_attr.getAttrValue(), "100004575"));
            /*attr.setAttrValues(KiteBeanUtils.copyPropsForList(operTypes, KiteAttrValue.class));
            if (KiteStringUtils.equals(apnType, "100003262") && KiteStringUtils.equalsAny(busiType, "100006958", "100006957")) {
                operTypes.removeIf(_attr -> !KiteStringUtils.equalsAny(_attr.getAttrValue(), "100004575"));
            }*/
            operTypes.removeIf(attrs -> !KiteStringUtils.equalsAny(attrs.getAttrValue(), "100004575"));
        }
        else if (KiteStringUtils.equals(ActionType.K.name(), inst.getActionType().name())
            || KiteStringUtils.equals(ActionType.M.name(), inst.getActionType().name())) {
            // 变更时 去掉新装按钮
            operTypes.removeIf(attrs -> KiteStringUtils.equals(attrs.getAttrValue(), "100004575"));
            attr.setAttrValues(KiteBeanUtils.copyPropsForList(operTypes, KiteAttrValue.class));
            if (KiteStringUtils.equals(apnType, "100003262") && KiteStringUtils.equalsAny(busiType, "100006958", "100006959")) {
                operTypes.removeIf(attrs -> !KiteStringUtils.equalsAny(attrs.getAttrValue(), "100004575", "100007391"));
            }
            else if (KiteStringUtils.equals(apnType, "100006957") && KiteStringUtils.equalsAny(busiType, "100006960")) {
                operTypes.removeIf(attrs -> KiteStringUtils.equalsAny(attrs.getAttrValue(), "100007391"));
            }
            else if (KiteStringUtils.equals(apnType, "100006957") && KiteStringUtils.equalsAny(busiType, "100006961")) {
                operTypes.removeIf(attrs -> !KiteStringUtils.equalsAny(attrs.getAttrValue(), "100004575", "100007395"));
            }
            else if (KiteStringUtils.equals(apnType, "100006957") && KiteStringUtils.equalsAny(busiType, "100006962")) {
                operTypes.removeIf(attrs -> KiteStringUtils.equalsAny(attrs.getAttrValue(), "100007391", "100007395"));
            }
            else if (KiteStringUtils.equals(apnType, "100006957") && KiteStringUtils.equalsAny(busiType, "100006963")) {
                operTypes.removeIf(attrs -> !KiteStringUtils.equalsAny(attrs.getAttrValue(), "100004575"));
            }
//            // 变更时,不使用默认值
//            if (KiteStringUtils.equals("100004575", attr.getValue())) {
//                attr.setValue("");
//                attr.setValueDesc("");
//                attr.setDefaultValue("");
//            }
        }
        attr.setAttrValues(KiteBeanUtils.copyPropsForList(operTypes, KiteAttrValue.class));
    }
}
